package com.jhte.scheduleJob.base.util;

import net.sf.json.JSON;
import net.sf.json.JSONSerializer;
import net.sf.json.xml.XMLSerializer;

import java.util.ArrayList;
import java.util.List;

public final class ObjectUtils {
	/**
	 * 
	 * 把对象转成XML格式字符串
	 */
	public static String toXml(Object o) {
		JSON jsonObject = JSONSerializer.toJSON(o);
		XMLSerializer xmlSerializer = new XMLSerializer();
		return xmlSerializer.write(jsonObject);
	}
	/**
	 * 
	 * 把对象转成json数据
	 */
	public static String toJSON(Object o) {
		JSON jsonObject = JSONSerializer.toJSON(o);
		return jsonObject.toString();
	}
	/**
	 * 将  1，2，3，4 类型的对象转成list
	 * @param o
	 * @return
	 */
	public static List<String> toList(Object o) {
		if (o != null) {
			List<String> list = new ArrayList<String>();
			String str = o.toString();
			String str2[] = str.split(",");
			for (int i = 0; i < str2.length; i++) {
				list.add(str2[i]);
			}
			return list;
		} else {
             return null;
		}
	}
}
